using System;
using UnityEngine;

public class JavaMessageHandler : MonoBehaviour
{
	public static bool interstitialPreloaded;

	public static bool rewardedInterstitialPreloaded;

	public static Action<int> OnRewardReceived;

	private void Awake()
	{
		OnRewardReceived = null;
		interstitialPreloaded = false;
		rewardedInterstitialPreloaded = false;
		UnityEngine.Object.DontDestroyOnLoad(this);
	}

	public void SetConsent(string consent)
	{
		PlayerPrefs.SetString("Consent", consent);
		switch (consent)
		{
		case "true":
			AdvertisementHandler.InstantiateDefault();
			AdvertisementHandler.EnableAds();
			break;
		case "false":
			AdvertisementHandler.InstantiateDefault();
			AdvertisementHandler.EnableAds();
			break;
		}
		PlayerPrefs.Save();
	}

	public void SetExp(string message)
	{
		int num = int.Parse(message);
		PlayerPrefs.SetInt("Exp", PlayerPrefs.GetInt("Exp") + num);
		AdvertisementHandler.lastTime = Time.time + 100f;
		PlayerPrefs.SetInt("Count2", 0);
		PlayerPrefs.Save();
		if (OnRewardReceived != null)
		{
			OnRewardReceived(num);
		}
	}

	public void PurchaseIap(string message)
	{
		if (message == "1")
		{
			Yup();
		}
		else
		{
			Nope();
		}
	}

	private void Yup()
	{
		if (PlayerPrefs.GetInt("tmp") == 7)
		{
			UnityEngine.Debug.Log("already purchased");
			return;
		}
		PlayerPrefs.SetInt("tmp", 7);
		PlayerPrefs.Save();
		AdvertisementHandler.DisableAds();
	}

	private void Nope()
	{
		PlayerPrefs.DeleteKey("tmp");
		PlayerPrefs.Save();
	}

	public void GetPrice(string message)
	{
		PlayerPrefs.SetInt("IapPrice", int.Parse(message));
	}

	public void AdLoaded(string message)
	{
		if (message == "1")
		{
			interstitialPreloaded = true;
		}
		else
		{
			interstitialPreloaded = false;
		}
	}

	public void RewardedAdLoaded(string message)
	{
		if (message == "1")
		{
			rewardedInterstitialPreloaded = true;
		}
		else
		{
			rewardedInterstitialPreloaded = false;
		}
	}
}
